package com.itheima.cloudproviderpayment8003.controller;


import com.itheima.cloudproviderpayment8003.service.PaymentService;
import com.itheima.pojo.CommentResult;
import com.itheima.pojo.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Value("${server.port}")
    private Integer port;
    @Autowired
    private PaymentService paymentService;

    @GetMapping("/findById/{id}")
    public CommentResult findById(@PathVariable("id") Integer id) {

        Payment payment = paymentService.findById(id);
        if (payment == null) {
            return new CommentResult(444, "未查询到数据!", null);
        }
        return new CommentResult(200, "查询成功! server.port=" + port, payment);
    }

    @PostMapping("/insert")
    public CommentResult insert(@RequestBody Payment payment) {
        int i = paymentService.insert(payment);

        if (i == 0) {
            return new CommentResult(400, "添加失败!", null);
        }
        return new CommentResult(200, "添加成功! server.port=" + port, i);
    }
}
